<template>
  <div class="home">
    <div class="title-container">
      <div class="search-content">
        <el-form :model="searchModel" :inline="true">
          <el-form-item>
            <el-input
              v-model="searchModel.userName"
              :disabled="detailsDisabled"
              placeholder="请输入聚合元素名称"
              prefix-icon="el-icon-search"
            />
          </el-form-item>
        </el-form>
        <div class="search-btn">
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="searchClick"
            size="medium"
          >搜索
          </el-button>
        </div>
      </div>
    </div>

    <el-card>
      <div class="addAccount">
        <perButton label="新建" type="primary" icon="el-icon-plus" size="medium" perms="PT_USER_ADD"
                   @click="handlerAccount"></perButton>
        <el-button
          type="success"
          icon="el-icon-refresh"
          size="medium"
          @click="refresh"
        >刷新
        </el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        row-key="id"
        border
        style="width: 100%;"
        class="elTable"
      >
        <el-table-column type="index" label="序号" width="50" align="center"/>
        <!--        <el-table-column prop="togetherCode" label="聚合元素编码" align="center"/>-->
        <el-table-column prop="togetherName" label="聚合元素名称" align="center"/>
        <el-table-column prop="togetherDesc" label="聚合元素描述" align="center"/>
        <!--        <el-table-column prop="tagCode" label="自定义标签编码" align="center"/>-->
        <el-table-column prop="tagName" label="自定义标签名称" align="center"/>
        <el-table-column prop="togetherRuleName" label="聚合规则名称" align="center"/>
        <el-table-column label="聚合数据类型" align="center">
          <template slot-scope="{row}">
            <el-tag :type="row.togetherDataType=='number'?'':'success'">
              {{ row.togetherDataType=="number"?"数值型":"布尔类型"}}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createByName" label="创建人" align="center"/>
        <el-table-column label="创建时间" align="center" prop="createTime">
          <template slot-scope="scope">
            {{ scope.row.createTime }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300" align="center">
          <template #default="{ row }">
            <perButton label="实列化" type="primary" size="mini" perms="PT_USER_EDIT"
                       @click="handlerInstantiationData(row)"></perButton>
            <perButton label="编辑" type="warning" size="mini" perms="PT_USER_EDIT"
                       @click="handlerEdit(row)"></perButton>
            <perButton label="删除" type="danger" size="mini" perms="PT_USER_DEL"
                       @click="handlerDelete(row)"></perButton>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        class="pagination"
        :total="count"
        :page.sync="pageIndex"
        :limit.sync="pageSize"
        @pagination="getAccountData"
      />
    </el-card>

    <!-- 新建 -->
    <yc-dialog ref="ycDialog" :dialogTitle="dialogTitle" :centerTitle="centerTitle">
      <template #content>
        <div class="dialog-content">
          <el-form
            ref="newAccountFormRef"
            :rules="newAccountModelRules"
            :model="newAccountModel"
            :disabled="detailsDisabled"
            label-width="110px"
          >
            <el-form-item label="聚合数据名称" prop="togetherName">
              <el-input v-model="newAccountModel.togetherName"/>
            </el-form-item>
            <el-form-item label="聚合数据描述">
              <el-input v-model="newAccountModel.togetherDesc" type="textarea" :rows="2"/>
            </el-form-item>
            <el-form-item label="数据标签" prop="tagCode">
              <el-cascader
                v-model="newAccountModel.tagCode"
                style="width: 100%;"
                ref="cascaderHandleRef"
                @change="handleSelectChange"
                :options="tagList"
                :props="tagProps"
                clearable></el-cascader>
            </el-form-item>
            <el-form-item label="数据规则" prop="togetherRuleCode">
              <el-select v-model="newAccountModel.togetherRuleCode" @change="selectChange" class="w-100">
                <el-option
                  v-for="item in polymerizationList"
                  :key="item.ruleMainCode"
                  :label="item.ruleMainName"
                  :value="item.ruleMainCode"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </div>
      </template>
      <template #footer>
        <el-button type="primary" :loading="addOrUpdateLoading" @click="dialogSave">确定</el-button>
        <el-button @click="$refs.ycDialog.dialogVisible = false">取消</el-button>
      </template>
    </yc-dialog>

    <!-- 实列化1 -->
    <yc-dialog ref="instantiationDialog1" :dialogTitle="dialogTitle" :show-center="false" dialog-width="60%">
      <template #content>
        <div class="dialog-content">
          <div class="d-flex justify-content-between align-items-center">
            <div class="d-flex">
              <div class="d-flex align-items-center mb-3 mr-5">
                <div class="mr-2 font-weight-bold font-15">单数据元：</div>
                <el-button type="primary" plain class="button-new-tag" size="small">数据元</el-button>
              </div>
              <div class="d-flex align-items-center mb-3">
                <div class="mr-2 font-weight-bold font-15">公式规则：</div>
                <el-button type="primary" plain class="button-new-tag" size="small">
                  {{gsgzList.find(item=>item.value == dataItemObj.mapString1).label}}
                </el-button>
              </div>
            </div>
            <el-button type="primary" size="mini" @click="openCheckDataDialog">实列化数据元
            </el-button>
          </div>
          <el-table
            :data="instantiationOneData"
            border
            style="width: 100%;"
            class="elTable"
          >
            <el-table-column type="index" label="序号" width="50" align="center"/>
            <el-table-column prop="dataValue" label="数据值" align="center"/>
            <el-table-column prop="dataValueName" label="数据值名称" align="center"/>
            <el-table-column prop="tagName" label="区域标签" align="center"/>
            <el-table-column prop="deviceName" label="设备名称" align="center"/>
            <el-table-column prop="parameterName" label="元素标签" align="center"/>
            <el-table-column label="数据类型" align="center">
              <template slot-scope="{row}">
                {{row.dataType=="0"?"设备数据":row.dataType=="1"?"聚合数据":"自定义运行数据"}}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </template>
      <template #footer>
        <el-button type="primary" :loading="addOrUpdateLoading" @click="instantiationDialogSave1">确定</el-button>
        <el-button @click="$refs.instantiationDialog1.dialogVisible = false">取消</el-button>
      </template>
    </yc-dialog>

    <!-- 实列化2 -->
    <yc-dialog ref="instantiationDialog2" :dialogTitle="dialogTitle" :show-center="false" dialog-width="60%">
      <template #content>
        <div class="dialog-content">
          <div class="d-flex justify-content-between align-items-center">
            <div class="d-flex">
              <div class="d-flex align-items-center mb-3 mr-5">
                <div class="mr-2 font-weight-bold font-15">数据元：</div>
                <el-button type="primary" plain class="button-new-tag" size="small">数据元集合</el-button>
              </div>
              <div class="d-flex align-items-center mb-3">
                <div class="mr-2 font-weight-bold font-15">数据元逻辑规则：</div>
                <el-button type="primary" plain class="button-new-tag" size="small">
                  {{sjyljghList.find(item=>item.value == dataItemObj.mapString1).label}}
                </el-button>
              </div>
            </div>
            <el-button type="primary" size="mini" @click="openCheckDataDialog">实列化数据元
            </el-button>
          </div>
          <el-table
            :data="instantiationTwoData"
            border
            style="width: 100%;"
            class="elTable"
          >
            <el-table-column type="index" label="序号" width="50" align="center"/>
            <el-table-column prop="dataValue" label="数据值" align="center"/>
            <el-table-column prop="dataValueName" label="数据值名称" align="center"/>
            <el-table-column prop="tagName" label="区域标签" align="center"/>
            <el-table-column prop="deviceName" label="设备名称" align="center"/>
            <el-table-column prop="parameterName" label="元素标签" align="center"/>
            <el-table-column label="数据类型" align="center">
              <template slot-scope="{row}">
                {{row.dataType=="0"?"设备数据":row.dataType=="1"?"聚合数据":"自定义运行数据"}}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="100" align="center">
              <template #default="{ row }">
                <perButton label="删除" type="danger" size="mini" perms="PT_USER_DEL"
                           @click="handlerInstantiationTwoDelete(row)"></perButton>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </template>
      <template #footer>
        <el-button type="primary" :loading="addOrUpdateLoading" @click="instantiationDialogSave2">确定</el-button>
        <el-button @click="$refs.instantiationDialog2.dialogVisible = false">取消</el-button>
      </template>
    </yc-dialog>

    <!-- 实列化3 -->
    <yc-dialog ref="instantiationDialog3" :dialogTitle="dialogTitle" :show-center="false" dialog-width="60%">
      <template #content>
        <div class="dialog-content">
          <div class="d-flex justify-content-between align-items-center">
            <div class="d-flex">
              <div class="d-flex align-items-center mb-4">
                <div class="mr-2 font-weight-bold font-15">聚合规则逻辑：</div>
                <div class="d-flex flex-wrap">
                  <el-button v-for="(item,index) in instantiationThreeData" :key="index"
                             type="primary" plain class="button-new-tag" size="small">
                    {{item.itemValueName}}
                  </el-button>
                </div>
              </div>
            </div>
          </div>

          <div v-if="dataItemObj.togetherDataType!=='number'" class="mb-1">
            <el-form
              ref="newBooleanFormRef"
              :rules="newBooleanModelRules"
              :model="newBooleanModel"
              label-width="115px"
              :inline="true"
            >
              <el-form-item label="满足条件ture" prop="trueOneCode">
                <el-select v-model="newBooleanModel.trueOneCode" class="w-100">
                  <el-option
                    v-for="item in baseBooleanList"
                    :key="item.dicCode"
                    :label="item.dicName"
                    :value="item.dicCode"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="满足条件false" prop="falseZeroCode">
                <el-select v-model="newBooleanModel.falseZeroCode" class="w-100">
                  <el-option
                    v-for="item in baseBooleanList"
                    :key="item.dicCode"
                    :label="item.dicName"
                    :value="item.dicCode"
                  />
                </el-select>
              </el-form-item>
            </el-form>
          </div>

          <div v-for="(item,index) in instantiationThreeData" :key="index">
            <div v-if="item.itemType=='0'" class="mb-4">
              <el-button type="primary" size="mini" @click="openCheckDataDialog(index)">实列化数据元{{index+1}}</el-button>
              <el-table
                :data="item.mapString1"
                border
                style="width: 100%;"
                class="mt-2"
              >
                <el-table-column type="index" label="序号" width="50" align="center"/>
                <el-table-column prop="dataValue" label="数据值" align="center"/>
                <el-table-column prop="dataValueName" label="数据值名称" align="center"/>
                <el-table-column prop="tagName" label="区域标签" align="center"/>
                <el-table-column prop="deviceName" label="设备名称" align="center"/>
                <el-table-column prop="parameterName" label="元素标签" align="center"/>
                <el-table-column label="数据类型" align="center">
                  <template slot-scope="{row}">
                    {{row.dataType=="0"?"设备数据":row.dataType=="1"?"聚合数据":"自定义运行数据"}}
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </template>
      <template #footer>
        <el-button type="primary" :loading="addOrUpdateLoading" @click="instantiationDialogSave3">确定</el-button>
        <el-button @click="$refs.instantiationDialog3.dialogVisible = false">取消</el-button>
      </template>
    </yc-dialog>

    <!-- 实列化 -->
    <yc-dialog ref="checkDataDialog" :dialogTitle="dialogTitle2" :show-center="false" dialog-width="65%">
      <template #content>
        <instantiateTable :selectionOrRadio="dataItemObj.messages" ref="instantiateTable"></instantiateTable>
      </template>
      <template #footer>
        <el-button type="primary" :loading="addOrUpdateLoading" @click="checkDataSave">确定</el-button>
        <el-button @click="$refs.checkDataDialog.dialogVisible = false">取消</el-button>
      </template>
    </yc-dialog>

    <!-- 封装操作后弹框 -->
    <global-message
      v-if="isGlobalMessageShow"
      @receive="receive"
      :message="message"
    />
  </div>
</template>

<script>
  import ycDialog from "@/components/pageDialog"
  import perButton from "@/components/permissionButton"
  import instantiateTable from "@/views/dataManage/polymerizationData/instantiateTable.vue"

  import {
    queryPage,
    insertByModel,
    updateByModel,
    deleteByModel,
    queryInitInfo,
    saveInitInfo,
    queryDetailList,
    queryBaseTogetherRuleMainList,
    queryBaseBooleanList
  } from "@/api/dataManage/polymerizationData"
  // import {
  //   queryList,
  // } from "@/api/basicsMessage/polymerizationRule.js"
  import { queryDeviceTagList } from "@/api/dataInsertConfig/internetOfThingsDevice"

  export default {
    components: {
      ycDialog,
      perButton,
      instantiateTable
    },
    data() {
      return {
        isGlobalMessageShow: false,
        message: "",

        tableData: [],
        dataItemObj: {},
        count: 0,
        pageIndex: 1,
        pageSize: 10,
        loading: false,

        searchModel: {
          userName: "",
          status: null //正常/停用状态（全部）
        },

        newAccountModel: {
          togetherName: "",
          togetherDesc: "",
          tagCode: "",
          togetherRuleCode: "",
          id: 0
        },
        newAccountModelRules: {
          togetherName: [{ required: true, message: "请输入聚合数据名称", trigger: "blur" }],
          tagCode: [{ required: true, message: "请选择数据标签", trigger: "change" }],
          togetherRuleCode: [{ required: true, message: "请选择数据规则", trigger: "change" }]
        },
        polymerizationList: [],
        tagList: [],
        tagProps: {
          label: "tagName",
          value: "tagCode",
          children: "childList",
          checkStrictly: true
        },
        isShow: true,
        dialogTitle: "",
        dialogTitle2: "",
        centerTitle: "",

        instantiationOneData: [],
        instantiationTwoData: [],
        instantiationThreeData: [],
        instantiationThreeData2: [],

        baseBooleanList: [],
        newBooleanModel: {
          trueOneCode: "",
          falseZeroCode: ""
        },
        newBooleanModelRules: {
          trueOneCode: [{ required: true, message: "请选择满足条件ture", trigger: "change" }],
          falseZeroCode: [{ required: true, message: "请选择满足条件false", trigger: "change" }]
        },

        instantiationThreeIndex: 0,
        // 公式规则
        gsgzList: [
          { value: "SUM-TODAY", label: "设备当日总和" },
          { value: "SUM-MONTH", label: "设备当月总和" },
          { value: "SUM-YEAR", label: "设备当年总和" },
          { value: "AVG-TODAY", label: "设备当日平均" },
          { value: "AVG-MONTH", label: "设备当月平均" },
          { value: "AVG-YEAR", label: "设备当年平均" },
          { value: "TOP-TODAY", label: "设备当日最高" },
          { value: "TOP-MONTH", label: "设备当月最高" },
          { value: "TOP-YEAR", label: "设备当年最高" },
          { value: "LOW-TODAY", label: "设备当日最低" },
          { value: "LOW-MONTH", label: "设备当月最低" },
          { value: "LOW-YEAR", label: "设备当年最低" },
          { value: "COUNT-TODAY", label: "设备当日累计" },
          { value: "COUNT-MONTH", label: "设备当月累计" },
          { value: "COUNT-YEAR", label: "设备当年累计" }
        ],
        sjyljghList: [
          { value: "SUM", label: "求和" },
          { value: "AVG", label: "求平均值" },
          { value: "TOP", label: "求最大值" },
          { value: "LOW", label: "求最小值" },
          { value: "COUNT", label: "累计" }
        ],

        detailsDisabled: false,
        addOrUpdateLoading: false
      }
    },
    created() {
      this.getAccountData()
    },
    methods: {
      /**
       * 获取表格方法
       */
      async getAccountData(tableInfo) {
        this.loading = true
        if (tableInfo) {
          const { userName, status } = tableInfo
          const { object } = await queryPage({
            pageIndex: this.pageIndex,
            pageSize: this.pageSize,
            userName,
            status
          })
          this.tableData = object.data
          this.count = object.count
          this.loading = false
        } else {
          const { object } = await queryPage({
            pageIndex: this.pageIndex,
            pageSize: this.pageSize
          })
          this.tableData = object.data
          this.count = object.count
          this.loading = false
        }
      },
      pagination(pageItem) {
        this.getAccountData(pageItem.page, pageItem.limit)
      },
      // 搜索按钮
      async searchClick() {
        this.getAccountData(this.searchModel)
      },

      /**
       * 删除按钮
       */
      async handlerDelete({ id }) {
        this.$confirm("确定删除此数据吗", "删除操作", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "error",
          center: true
        }).then(async () => {
          const { message, status } = await deleteByModel({ id })
          if (status == "200") {
            this.getAccountData()
            this.isGlobalMessageShow = true
            this.message = "success"
          } else {
            this.message = "error"
          }
        })
      },

      /**
       * 新建
       * */
      async handlerAccount() {
        this.dialogTitle = "添加"
        this.centerTitle = "添加"

        this.detailsDisabled = false
        this.addOrUpdateLoading = false
        this.$refs.ycDialog.dialogVisible = true

        Object.keys(this.newAccountModel).forEach((item) => {
          this.newAccountModel[item] = ""
        })

        this.queryDeviceTagList()
        this.queryDataRuleList()
      },
      // 数据标签
      async queryDeviceTagList() {
        await queryDeviceTagList().then(res => {
          const tempArr = res.object || {}

          this.tagList = tempArr.ownerList
        })
      },
      handleSelectChange(node) {
        // if (!this.$refs.cascaderHandleRef.getCheckedNodes()[0]?.hasChildren) {
        this.$refs.cascaderHandleRef.dropDownVisible = false
        // }
      },
      // 数据规则
      async queryDataRuleList() {
        await queryBaseTogetherRuleMainList().then(res => {
          const tempArr = res.object || []
          this.polymerizationList = tempArr
        })
      },
      selectChange(val) {
        const tempObj = this.polymerizationList.find(item => {
          return item.ruleMainCode == val
        })
        this.isShow = tempObj.resType == "bo"
      },
      /**
       * 修改
       */
      async handlerEdit(row) {
        this.dialogTitle = "编辑"
        this.centerTitle = "编辑"

        this.newAccountModel.id = row.id
        this.newAccountModel.togetherName = row.togetherName
        this.newAccountModel.togetherDesc = row.togetherDesc
        this.newAccountModel.tagCode = row.tagAllCode ? row.tagAllCode.split("-") : []
        this.newAccountModel.togetherRuleCode = row.togetherRuleCode

        await this.queryDeviceTagList()
        await this.queryDataRuleList()

        this.selectChange(row.togetherRuleCode)

        this.addOrUpdateLoading = false
        this.detailsDisabled = false
        this.$refs.ycDialog.dialogVisible = true
      },

      dialogSave() {
        this.$refs.newAccountFormRef.validate(async (v) => {
          if (v) {
            this.addOrUpdateLoading = true
            if (this.detailsDisabled) {
              // 详情的确定
              this.$refs.ycDialog.dialogVisible = false
            } else if (this.newAccountModel.id) {
              const { id, togetherName, togetherDesc, tagCode, togetherRuleCode } = this.newAccountModel
              const { message, status } = await updateByModel({
                id,
                togetherName, togetherDesc,
                tagCode: tagCode[tagCode.length - 1],
                togetherRuleCode
              })
              if (status == 200) {
                this.getAccountData()
                this.$refs.ycDialog.dialogVisible = false
                this.$message.success(message)
              }
            } else {
              const { togetherName, togetherDesc, tagCode, togetherRuleCode } = this.newAccountModel
              const { message, status } = await insertByModel({
                togetherName, togetherDesc,
                tagCode: tagCode[tagCode.length - 1],
                togetherRuleCode
              })
              if (status == 200) {
                this.getAccountData()
                this.$refs.ycDialog.dialogVisible = false
                this.$message.success(message)
              }
            }
            this.addOrUpdateLoading = false
          }
        })
      },


      // 分逻辑打开不同的实列化弹窗
      async handlerInstantiationData(row) {
        this.dialogTitle = "实例化聚合数据"
        this.dataItemObj = JSON.parse(JSON.stringify(row))

        await this.queryInitInfo()

        this.addOrUpdateLoading = false
        if (row.messages == "0") {
          this.$refs.instantiationDialog1.dialogVisible = true
        } else if (row.messages == "1") {
          this.$refs.instantiationDialog2.dialogVisible = true
        } else {
          await this.queryDetailList()
          await this.queryBaseBooleanList()
          this.$refs.instantiationDialog3.dialogVisible = true
        }
      },
      // 回显接口
      async queryInitInfo() {
        await queryInitInfo({
          togetherCode: this.dataItemObj.togetherCode
        }).then(res => {
          this.instantiationOneData = res.object
          this.instantiationTwoData = res.object
          this.instantiationThreeData2 = res.object
        })
      },
      // 实列化3查询接口
      async queryDetailList() {
        await queryDetailList({
          ruleMainCode: this.dataItemObj.togetherRuleCode
        }).then(res => {
          let tempArr = res.object || []
          let count = 0
          // const tempArr2 = this.instantiationThreeData.filter(item => {
          //   return item.itemType == '0'
          // })
          for (let i = 0; i < tempArr.length; i++) {
            if (tempArr[i].itemType == "0") {
              tempArr[i].mapString1 = [this.instantiationThreeData2[count]]
              count++
            }
          }
          this.instantiationThreeData = tempArr
          // this.instantiationThreeData2 = tempArr
        })
      },

      queryBaseBooleanList() {
        queryBaseBooleanList().then(res => {
          this.baseBooleanList = res.object
        })
      },

      // 打开数据源弹窗
      openCheckDataDialog(index) {
        this.dialogTitle2 = "数据元查询"

        this.instantiationThreeIndex = index ? index : 0

        this.addOrUpdateLoading = false
        this.$refs.checkDataDialog.dialogVisible = true
      },
      // 分逻辑保存数据源，并关闭弹窗
      checkDataSave() {
        if (this.dataItemObj.messages == "0") {
          this.instantiationOneData = [this.$refs.instantiateTable.selectedRow]
        } else if (this.dataItemObj.messages == "1") {
          let tempArr = this.$refs.instantiateTable.selectedRows
          for (let j = 0; j < tempArr.length; j++) {
            let tempIndex = this.instantiationTwoData.findIndex(item => item.messages == tempArr[j].messages)
            if (tempIndex == -1) {
              this.instantiationTwoData.push(tempArr[j])
            }
          }
        } else {
          this.instantiationThreeData[this.instantiationThreeIndex].mapString1 = [this.$refs.instantiateTable.selectedRow]
        }

        this.$refs.checkDataDialog.dialogVisible = false
      },
      //实列化2删除
      handlerInstantiationTwoDelete(row) {
        let tempIndex = this.instantiationTwoData.findIndex(item => item.messages == row.messages)
        this.instantiationTwoData.splice(tempIndex, 1)
      },
      //实列化1保存
      instantiationDialogSave1() {
        if (this.instantiationOneData.length == 1) {
          this.addOrUpdateLoading = true
          saveInitInfo({
            togetherCode: this.dataItemObj.togetherCode,
            initData: this.instantiationOneData[0].messages
          }).then(res => {
            if (res.status == 200) {
              this.getAccountData()
              this.$refs.instantiationDialog1.dialogVisible = false
              this.$message.success(res.message)
            }
            this.addOrUpdateLoading = false
          })
        } else {
          this.$message({
            message: "请选择数据元",
            type: "warning"
          })
        }
      },
      //实列化2保存
      instantiationDialogSave2() {
        if (this.instantiationTwoData.length > 0) {
          this.addOrUpdateLoading = true

          let tempArr = this.instantiationTwoData.map(item => item.messages)

          saveInitInfo({
            togetherCode: this.dataItemObj.togetherCode,
            initData: tempArr.join("&")
          }).then(res => {
            if (res.status == 200) {
              this.getAccountData()
              this.$refs.instantiationDialog2.dialogVisible = false
              this.$message.success(res.message)
            }
            this.addOrUpdateLoading = false
          })
        } else {
          this.$message({
            message: "请选择数据元",
            type: "warning"
          })
        }
      },
      //实列化3保存
      instantiationDialogSave3() {
        if (this.dataItemObj.togetherDataType == "number") {
          const tempArr = this.instantiationThreeData.filter(item => {
            return item.itemType == "0"
          })
          let tempArr2 = []
          for (let i = 0; i < tempArr.length; i++) {
            if (tempArr[i].mapString1.length !== 1) {
              this.$message({
                message: "请选择数据元",
                type: "warning"
              })
              return
            }

            tempArr2.push(tempArr[i].mapString1[0].messages)
          }
          this.addOrUpdateLoading = true
          saveInitInfo({
            togetherCode: this.dataItemObj.togetherCode,
            initData: tempArr2.join("&")
          }).then(res => {
            if (res.status == 200) {
              this.getAccountData()
              this.$refs.instantiationDialog3.dialogVisible = false
              this.$message.success(res.message)
            }
            this.addOrUpdateLoading = false
          })
        } else {
          this.$refs.newBooleanFormRef.validate(async (v) => {
            if (v) {
              const tempArr = this.instantiationThreeData.filter(item => {
                return item.itemType == "0"
              })
              let tempArr2 = []
              for (let i = 0; i < tempArr.length; i++) {
                if (tempArr[i].mapString1.length !== 1) {
                  this.$message({
                    message: "请选择数据元",
                    type: "warning"
                  })
                  return
                }

                tempArr2.push(tempArr[i].mapString1[0].messages)
              }
              this.addOrUpdateLoading = true
              saveInitInfo({
                togetherCode: this.dataItemObj.togetherCode,
                initData: tempArr2.join("&"),
                ...this.newBooleanModel
              }).then(res => {
                if (res.status == 200) {
                  this.getAccountData()
                  this.$refs.instantiationDialog3.dialogVisible = false
                  this.$message.success(res.message)
                }
                this.addOrUpdateLoading = false
              })
            }
          })
        }
      },


      /**
       * 刷新
       */
      refresh() {
        this.searchModel = {
          userName: "",
          status: null
        }
        this.getAccountData()
      },

      /**
       * globalMessage的知道按钮的方法
       * */
      receive() {
        this.isGlobalMessageShow = false
      }
    }
  }
</script>

<style lang="scss" scoped>
  .status {
    display: inline-block;
    padding: 0 10px;
  }

  .title-container {
    display: flex;
    justify-content: flex-end;
    height: 60px;

    .search-content {
      margin-left: 20px;
      display: flex;
    }

    .addAccount {
      margin: 10px 20px;
    }
  }

  .pagination {
    display: flex;
    justify-content: flex-end;
  }


  .footer {
    height: 360px;
    display: flex;
    align-items: flex-end;
    // justify-content: st-end;
    padding: 5px 20px;
  }
</style>
